﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;
using Sample;
using Debugging;

namespace ConfigurationTester
{
    class Program
    {
        static void Main(string[] args)
        {
            string tempConfigFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".config");
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap { ExeConfigFilename = tempConfigFile };
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

            // Create configuration
            SampleConfigurationSection section = new SampleConfigurationSection();
            config.Sections.Add("sample", section);
            section.Foo.Baz = new CustomType { Height = 42, Width = 314, Depth = 313 };

            section.Bars.Add(new Bar { Crackle = 3.14F, Snap = true });
            //section.Bars.Add(new Bar { Crackle = 2.71828F, Snap = false });

            config.Save();

            // Load configuration
            config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            section = config.Sections["sample"] as SampleConfigurationSection;

            Console.WriteLine(section.Foo.Baz.Height);
            Console.WriteLine(section.Foo.Baz.Width);
            Console.WriteLine(section.Foo.Baz.Depth);

            if (File.Exists(tempConfigFile))
                File.Delete(tempConfigFile);

            Console.ReadLine();
        }
    }
}
